<?php
namespace Home\Controller;
use Think\Controller;
class GameController extends Controller {
    public function index() {
        $game = D('Game');
        $list = $game->order('id desc')->limit(9)->select();
        $r = D('Resource');
        foreach ($list as &$v) {
            $pic = $r->where('id=%d', $v['pid'])->find();
            $v['path'] = $pic['path'];
            $v['href'] = U('view',array('id'=>$v['flash']));
        }

        switch(count($list)) {
            case 9:$this->assign('game9', $list[8]);
            case 8:$this->assign('game8', $list[7]);
            case 7:$this->assign('game7', $list[6]);
            case 6:$this->assign('game6', $list[5]);
            case 5:$this->assign('game5', $list[4]);
            case 4:$this->assign('game4', $list[3]);
            case 3:$this->assign('game3', $list[2]);
            case 2:$this->assign('game2', $list[1]);
            case 1:$this->assign('game1', $list[0]);
        }

        $this->display('./Public/game.html');
    }

    public function view($id) {
        $r = D('Resource');
        $flash = $r->where("id=$id")->find();
        $this->assign('path', $flash['path']);
        $this->display('./Public/flash.html');
    }
}